package HLLib.userControl.HLPanelPickUp;

import javax.microedition.lcdui.Image;

import HLLib.base.HLGraphics;
import HLLib.base.HLGraphics_H;
import HLLib.base.HLImage;
import HLLib.base.HLString;
import HLLib.control.HLPanel;
import HLLib.control.HLPhotoFrame;
import HLLib.handfere.HLCommunityData.HLGroup.HLGroup;

public class HLGroupPanel extends HLPanel {
    public static final int PHOTO_X = 3;

    public static final int PHOTO_Y = 5;

    public static final int PHOTO_TO_TEXT = 10;

    public static final int TEXT_Y = 2;

    public int selectColor = 0xffff00;

    public int color = 0xffecf3fd;

    public HLGroup group;

    Image img;

    HLPhotoFrame photoFrame;

    public HLGroupPanel(HLGroup group, Image img) {
        dock = DOCK_STYLE_TOP;
        tabelStop = true;
        this.img = img;
        this.group = group;
        this.backcolor = -1;

        photoFrame = new HLPhotoFrame(group.icon);
        photoFrame.x = PHOTO_X;
        photoFrame.y = PHOTO_Y;

        Add(photoFrame);

        this.height = Math.max(TEXT_Y + HLGraphics.StringHeight() + TEXT_Y + HLGraphics.StringHeight() + 2, photoFrame.height + PHOTO_Y * 2);
        group.icon.StartLoad();
    }

    public void Logic() {
        super.Logic();
        if (IsFocus()) {
            RefreshEvent(GetScreenX(), GetScreenY(), GAME_BUTTON_ACTION);
        }
    }

    public void Refresh() {
        super.Refresh();

    }

    public void Render(HLGraphics g) {
        // super.Render(g);
        int screenX = GetScreenX();
        int screenY = GetScreenY();
        g.FillRect(screenX, screenY, width, height, 0xffffff);
        if (IsFocus()) {
            // g.DrawImageFillRect(new HLImage(img[1]), screenX, screenY, width,
            // img[1].getHeight(), HLGraphics_H.TRANS_NONE);
            // g.DrawImageFillRect(new HLImage(img[0]), screenX, screenY +
            // height - img[0].getHeight(), width, img[1].getHeight(),
            // HLGraphics_H.TRANS_NONE);
            g.FillRect(screenX, screenY, width, height, HLPanelGroup.SELECTED_COLOR);// d0d9f2);//0xd0ebf2);
            g.DrawImage(new HLImage(img), screenX + width - img.getWidth() - 5, screenY + (height - img.getHeight() >> 1), HLGraphics_H.TRANS_NONE);
        }
        int offsetX = screenX + 4;
        int offsetY = screenY + TEXT_Y;

        g.DrawString(new HLString(group.name), offsetX + photoFrame.width + PHOTO_TO_TEXT, offsetY, 0xff4b4b4b, 0, TEXT_STYLE_NORMAL);
        photoFrame.Render(g);
    }
}
